//
//  LLoggerShare.m
//  LLoger
//
//  Created by yiban on 16/1/26.
//  Copyright © 2016年 liuchengbin. All rights reserved.
//

#import "LLoggerShare.h"
#import "CocoaLumberjack.h"
#ifdef DEBUG
    static const DDLogLevel ddLogLevel = DDLogLevelVerbose;
#else
    static const DDLogLevel ddLogLevel = DDLogLevelOff;
#endif
@interface LLoggerShare()
{
    
}
@property(nonatomic,strong)DDTTYLogger *ttyLogger;
@property(nonatomic,strong)DDFileLogger *fileLogger;

@end
@implementation LLoggerShare
@synthesize ttyLogger=_ttyLogger;
@synthesize fileLogger=_fileLogger;

+ (instancetype)sharedLLoggerShare
{
    static LLoggerShare *instance;
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        instance = [[LLoggerShare alloc] init];
    });
    return instance;
}

- (id)init {
    self = [super init];
    if (self) {
        if (!_ttyLogger) {
            _ttyLogger = [[DDTTYLogger alloc] init];
            [DDLog addLogger:_ttyLogger];
            DDLogVerbose(@"_ttyLogger init");
        }
       
    }
    return self;
}
-(void)dealloc
{
    self.ttyLogger=nil;
    if(_fileLogger)
    {
        self.fileLogger=nil;
    }
    DDLogVerbose(@"");
}
- (void)setFileModel:(BOOL)isFile
{
    if (isFile) {
        if (!_fileLogger) {
            _fileLogger = [[DDFileLogger alloc] init];
            _fileLogger.rollingFrequency = 60 * 60 * 24;
            _fileLogger.logFileManager.maximumNumberOfLogFiles = 7;
            [DDLog addLogger:_fileLogger];
            DDLogVerbose(@"_fileLogger init");
        }
    }
}
- (void)yblogInfo:(const char *)func line:(int)line msg:(NSString *)fmt, ...
{
    va_list args;
    va_start(args, fmt);
    NSString *message = [[NSString alloc] initWithFormat:fmt arguments:args];
    NSString *strr =[NSString stringWithFormat:@"[%@]%s[LINE:%d] %@", @"Info", func, line, message];
    DDLogInfo(@"%@",strr);
    va_end(args);
}

- (void)yblogError:(const char *)func line:(int)line msg:(NSString *)fmt, ...
{
    va_list args;
    va_start(args, fmt);
    NSString *message = [[NSString alloc] initWithFormat:fmt arguments:args];
    NSString *strr =[NSString stringWithFormat:@"[%@]%s[LINE:%d] %@", @"Error", func, line, message];
    DDLogError(@"%@",strr);
    va_end(args);
}
- (void)yblogWarn:(const char *)func line:(int)line msg:(NSString *)fmt, ...
{
    va_list args;
    va_start(args, fmt);
    NSString *message = [[NSString alloc] initWithFormat:fmt arguments:args];
    NSString *strr =[NSString stringWithFormat:@"[%@]%s[LINE:%d] %@", @"Warn", func, line, message];
    DDLogWarn(@"%@",strr);
    va_end(args);
}
- (void)yblogVerbose:(const char *)func line:(int)line msg:(NSString *)fmt, ...
{
    va_list args;
    va_start(args, fmt);
    NSString *message = [[NSString alloc] initWithFormat:fmt arguments:args];
    NSString *strr =[NSString stringWithFormat:@"[%@]%s[LINE:%d] %@", @"Verbose", func, line, message];
    DDLogVerbose(@"%@",strr);
    va_end(args);
}

@end
